<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>苞米面 C++ 模板库: bmm/string_algo.hpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">苞米面 C++ 模板库
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_3855b158c164314995fac6a2abe3aa9c.html">bmm</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">string_algo.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="string__algo_8hpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef _BMM_STRING_ALGO_HPP_</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define _BMM_STRING_ALGO_HPP_</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="global_8hpp.html">global.hpp</a>&quot;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160; </div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;_BMM_NAMESPACE_BEGIN_</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> _InputIterator, <span class="keyword">typename</span> _String&gt;</div>
<div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="string__algo_8hpp.html#ae137eb03181b83d8743769f1a675dfd2">   25</a></span>&#160;_String <a class="code" href="string__algo_8hpp.html#ae137eb03181b83d8743769f1a675dfd2">string_join</a>(_InputIterator __first, _InputIterator __last, <span class="keyword">const</span> _String &amp;__sep)</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;{</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    _String __s;</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    <span class="keywordflow">if</span> (__first != __last)</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        __s = *__first++;</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keywordflow">for</span> (; __first != __last; ++__first)</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        __s += __sep + *__first;</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;    <span class="keywordflow">return</span> __s;</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;}</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160; </div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> _ArrayT, <span class="keyword">typename</span> _String&gt;</div>
<div class="line"><a name="l00045"></a><span class="lineno"><a class="line" href="string__algo_8hpp.html#a4d7ab60086dcea20a9abebbdc8cd1a1d">   45</a></span>&#160;_String <a class="code" href="string__algo_8hpp.html#ae137eb03181b83d8743769f1a675dfd2">string_join</a>(<span class="keyword">const</span> _ArrayT &amp;__arr, <span class="keyword">const</span> _String &amp;__sep)</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;{</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="string__algo_8hpp.html#ae137eb03181b83d8743769f1a675dfd2">string_join</a>(__arr.begin(), __arr.end(), __sep);</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;}</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160; </div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> _String, <span class="keyword">typename</span> _ArrayT = std::vector&lt;_String&gt;&gt;</div>
<div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="string__algo_8hpp.html#a6fd0f54a47c71e1a31792859618f5ac4">   59</a></span>&#160;_ArrayT <a class="code" href="string__algo_8hpp.html#a6fd0f54a47c71e1a31792859618f5ac4">string_split</a>(<span class="keyword">const</span> _String &amp;__s, <span class="keyword">const</span> _String &amp;__sep)</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;{</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    std::size_t __pos = __s.find(__sep);</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    std::size_t __first_pos = 0;</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    _ArrayT __result;</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="keywordflow">while</span> (__pos != std::string::npos)</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    {</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;        __result.push_back(__s.substr(__first_pos, __pos - __first_pos));</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;        __first_pos = __pos + __sep.size();</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        __pos = __s.find(__sep, __pos + __sep.size());</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    }</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    <span class="keywordflow">if</span> (__first_pos != __s.size())</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;        __result.push_back(__s.substr(__first_pos));</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    <span class="keywordflow">return</span> __result;</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;}</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160; </div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;_BMM_NAMESPACE_END_</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160; </div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;<span class="preprocessor">#endif // _BMM_STRING_ALGO_HPP_</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="astring__algo_8hpp_html_a6fd0f54a47c71e1a31792859618f5ac4"><div class="ttname"><a href="string__algo_8hpp.html#a6fd0f54a47c71e1a31792859618f5ac4">string_split</a></div><div class="ttdeci">_ArrayT string_split(const _String &amp;__s, const _String &amp;__sep)</div><div class="ttdoc">将一个字符串按照 __sep 分割成一个字符串容器</div><div class="ttdef"><b>Definition:</b> string_algo.hpp:59</div></div>
<div class="ttc" id="aglobal_8hpp_html"><div class="ttname"><a href="global_8hpp.html">global.hpp</a></div><div class="ttdoc">全局设置</div></div>
<div class="ttc" id="astring__algo_8hpp_html_ae137eb03181b83d8743769f1a675dfd2"><div class="ttname"><a href="string__algo_8hpp.html#ae137eb03181b83d8743769f1a675dfd2">string_join</a></div><div class="ttdeci">_String string_join(_InputIterator __first, _InputIterator __last, const _String &amp;__sep)</div><div class="ttdoc">将一个范围内的字符串连接成一个字符串</div><div class="ttdef"><b>Definition:</b> string_algo.hpp:25</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
